import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import departmentsAsync from './modules/departments'
import employeesAsync from './modules/employees'
// 引入多个动态路由模块
import permissionRouterAsync from './modules/permissions'
import settingRouterAsync from './modules/settings'
import salarysRouterAsync from './modules/salarys'
import approvalsAsync from './modules/approvals'
import attendancesAsync from './modules/attendances'
import social_securitysAsync from './modules/social_securitys'

// 动态路由表
export const asyncRoutes = [
  departmentsAsync,
  employeesAsync,
  permissionRouterAsync,
  settingRouterAsync,
  salarysRouterAsync,
  approvalsAsync,
  attendancesAsync,
  social_securitysAsync
]
/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
// 填写路由的规则
// 静态路由表
export const constantRoutes = [
  {
    path: '/import',
    component: () => import('@/views/import/index'),
    hidden: true
  },
  {
    path: '/Father',
    component: () => import('@/views/demo/native/Father'),
    hidden: true
  },
  {
    path: '/Son',
    component: () => import('@/views/demo/native/Son'),
    hidden: true
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import(/* webpackChunkName:"404"*/'@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  }
  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  // 指定路由规则,合并静态路由和动态路由生成最终列表
  routes: [...constantRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
